<template>
	<view class="enterprise-details">
		<view class="details-card">
			<view class="card-title">企业基本信息</view>
			<view class="info-item">
				<view class="label">企业名称：</view>
				<view class="value">{{companyInfo.companyName}}</view>
			</view>
			<view class="info-item">
				<view class="label">统一社会信用代码：</view>
				<view class="value">{{companyInfo.creditCode}}</view>
			</view>
			<view class="info-item">
				<view class="label">经营状态：</view>
				<view class="value">{{companyInfo.status}}</view>
			</view>
			<view class="info-item">
				<view class="label">成立日期：</view>
				<view class="value">{{companyInfo.startDate}}</view>
			</view>
			<view class="info-item">
				<view class="label">注册资本：</view>
				<view class="value">{{companyInfo.registCapi}}</view>
			</view>
			<view class="info-item">
				<view class="label">企业类型：</view>
				<view class="value">{{companyInfo.econKind}}</view>
			</view>
			<view class="info-item">
				<view class="label">法定代表人：</view>
				<view class="value">{{companyInfo.operName}}</view>
			</view>
			<view class="info-item">
				<view class="label">企业规模：</view>
				<view class="value">{{companyInfo.personScope}}</view>
			</view>
			<view class="info-item">
				<view class="label">注册地址：</view>
				<view class="value">{{companyInfo.address}}</view>
			</view>
			<view class="info-item">
				<view class="label">经营范围：</view>
				<view class="value">{{companyInfo.scope}}</view>
			</view>
		</view>
	</view>
</template>

<script>
import { getCompanyByCode } from '@/api/api.js'

export default {
	data() {
		return {
			companyInfo: {}
		}
	},
	onLoad(options) {
		console.log('onLoad options:', options)
		if (options.creditCode) {
			this.getCompanyInfo(options.creditCode, options.companyName)
		} else {
			console.log('未获取到企业统一社会信用代码')
		}
	},
	methods: {
		async getCompanyInfo(creditCode, companyName) {
			if (!creditCode) {
				uni.showToast({
					title: '企业信用代码不能为空',
					icon: 'none'
				})
				return
			}
			try {
				const result = await getCompanyByCode({ CreditCode: creditCode })
				console.log('企业信息详情数据：', result)
				if (result.code === 0) {
					this.companyInfo = result.data || {}
				} else {
					uni.showToast({
						title: result.message || '获取企业信息失败',
						icon: 'none'
					})
				}
			} catch (error) {
				console.error('获取企业信息失败：', error)
				uni.showToast({
					title: '获取企业信息失败',
					icon: 'none'
				})
			}
		}
	}
}
</script>

<style lang="scss">
page{
	background: #f7f8fc;
}
.enterprise-details {
	padding: 30rpx 24rpx;
	background: #f7f8fc;
	
	.details-card {
		background: #ffffff;
		border-radius: 20rpx;
		padding: 30rpx;
		
		.card-title {
			font-size: 32rpx;
			color: #202020;
			font-weight: bold;
			margin-bottom: 30rpx;
		}
		
		.info-item {
			margin-bottom: 20rpx;
			padding: 0 0 20rpx;
			border-bottom: 1px dashed #cccccc;
			
			.label {
				font-size: 32rpx;
				color: #333333;
			}
			
			.value {
				padding: 10rpx 0 0;
				font-size: 28rpx;
				color: #999999;
			}
		}
	}
}
</style>